#include <iostream>
#include <signal.h>
#include <unistd.h>

using namespace std;

void showPending(sigset_t* pending)
{
    for (int sig = 1; sig <= 31; sig++)
    {
        if (sigismember(pending, sig)) cout << "1";
        else cout << "0";
    }
    cout << endl;
}

void handler(int signum)
{
    cout << "获取了一个信号" << signum << endl;

    sigset_t pending;
    int c = 10;
    while (true)
    {
        sigpending(&pending);
        showPending(&pending);
        c--;
        if (!c) break;
    }
}

int main()
{
    struct sigaction act, oact;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    act.sa_handler = handler;

    //设置进当前调用进程的pcb中
    sigaction(2, &act, &oact);

    cout << "default action : " << (int)(oact.sa_handler) << endl;

    while (true) sleep(1);

    return 0;
}